<?php

namespace Admin\Controller;

/**
 * APP引导管理
 */
class GuideController extends CommonController {
    /**
     * 列表
     */
    public function index(){
        $params = array(
            'showpage' => 10,
            'order' => 'sort desc'
        );
        $redata = D('Guide')->listData($params);
        $this->assign('list',$redata['list']);
        $this->assign('page',$redata['page']);
        $this->display();
    }
    /**
     * 编辑
     */
    public function addguide(){
        $id = I('GET.id');
        $Guide = M('guide');
        if(!empty($id)){
            $map['id'] = $id;
            $list = $Guide -> where($map) -> find();
        }
        $this->assign('list',$list);
        $this->display();
    }
    /**
     * 保存
     */
    public function saveguide(){
        $id = I('POST.id');
        $Guide = M('guide');
        $data = $Guide -> create();
        $data['time'] = time();
        if(empty($id)){
            $Res = $Guide -> add($data);
        }else{
            $Res = $Guide -> save($data);
        }
        if($Res>0){
            $this->success('操作成功！',U('index'));
        }else{
            $this->error('操作失败！');
        }
    }
    /**
     * 删除
     */
    public function delguide(){
        $ids=I('post.id');
        if (empty($ids)) $this->error('请选择要操作的对象！');
        $map=array(
            'id' => array('in', $ids)
            );
        $result = D('Guide')->deleteData($map);
        if($result){
            $this->success('删除成功',U('index'));
        }else{
            $this->error('删除失败');
        }
    }
    /**
     * 排序
     */
    public function setSort(){
        $id = I('POST.id');
        $sort = I('POST.sort');
        if (empty($id)){
            $this->error('请选择要修改的信息！','',true);
        }
        $map['id'] = array('eq',$id);
        $data['sort'] = $sort;
        $data['time'] = time();
        $Res = M('guide')->where($map)->save($data);
        if ($Res>0){
            $this->success('修改成功！');
        }else{
            $this->error('修改失败！');
        }
    }
    /**
     * 状态
     */
    public function setStatus(){
        $id = I('POST.id');
        $status = I('POST.status');
        if(empty($id)){
            $this->error('请选择要修改的信息！','',true);
        }
        if($status == 1){
            $status = 0;
        }else{
            $status = 1;
        }
        $map['id'] = array('eq',$id);
        $data['status'] = $status;
        $data['time'] = time();
        $Res = M('guide')->where($map)->save($data);
        if ($Res>0){
            $this->success('修改成功！');
        }else{
            $this->error('修改失败！');
        }
    }
}